#!/bin/sh

# If we are running on Linux we re-compile the utilities since
# the package might be running on a different architecture
# or be running on 32 rather than 64 bit.

if [ -d /opt/truecl/etc ]
then
	cd /opt/truecl/etc
	chmod 600 *.xml
fi

if [ `uname` = Linux ]
then
	cd /opt/truecl/utils
	chmod +x make
	sh ./make

	r=$?
	if [ $r != 0 ]
	then
		echo "Error: Failed to compile utilities inn /opt/truecl/utils." >&2
		exit 1
	fi

	# Now the main utilities have been made, look at compilation 
	# of the Perl/C interfaces.

	cd /opt/truecl/utils/perl_interfaces/miitoollib
	perl Makefile.PL
	r=$?
	if [ $r != 0 ]
	then
		echo "Error: Unable to make 'miitoollib' make file." >&2
		exit 1
	fi
	make
	r=$?
	if [ $r != 0 ]
	then
		echo "Error: Unable to make 'miitoollib' tool." >&2
		exit 1
	fi
	make install
	r=$?
	if [ $r != 0 ]
	then
		echo "Error: Unable to install 'miitoollib' tool." >&2
		exit 1
	fi
fi

if [ ! -d /opt/truecl/log ] && [ -d /opt/truecl ]
then
	mkdir -p -m 750 /opt/truecl/log
fi

if [ -f /etc/manpath.config ]
then
	y=`grep /opt/truecl/man /etc/manpath.config`
	if [ -z "$y" ]
	then
		echo "MANDATORY_MANPATH	/opt/truecl/man" >>/etc/manpath.config
	fi
fi

if [ -f /etc/man.config ]
then
	y=`grep /opt/truecl/man /etc/man.config`
	if [ -z "$y" ]
	then
		echo "MANPATH /opt/truecl/man" >>/etc/man.config
	fi
fi

exit 0
